﻿<!doctype html>
<%@ LANGUAGE="javascript" %>
<!--#include file ="Includes/JSON2.asp"-->
<!--#include file ="Includes/DB.asp"--> 
<!--#include file ="Includes/ASPHelpers.asp"-->


<%
	var h=Helpers;
	
	var searchWhat = Request.Form("SearchWhat").Item;
	if (searchWhat == undefined) searchWhat = "";
	
//build query
if (searchWhat != ""){
	
	var rs, queryName;
	
	db = new DB.DataCall();
	db.ConnectionString = 	DB.ConnectionStrings.Hub;
	db.CommandType = 		DB.CommandTypes.StoredProc;

	switch (searchWhat){
		case "Account":
			var AccountNumber = "" + Request.Form("AccountNumber");
			
			if (Helpers.IsNumeric(AccountNumber)){
				queryName = "getHSCustLikeAcctNumber";
				db.AddParameter("@AccountNumber", DB.DataTypes.String, AccountNumber);
			}
			else{
				queryName = "getNonHSCustLikeContractID"
				db.AddParameter("@ContractID", DB.DataTypes.String, AccountNumber);
			}
			
			break;
			
			
		case "NameAddress":
			var firstname = "" + Request.Form("firstname");
			var lastname =	"" + Request.Form("lastname");
			var address =	"" + Request.Form("address");
			
			queryName = "getHSandNonHSCustLikeNameOrAddress";
			db.AddParameter("@FirstName", DB.DataTypes.String, firstname);
			db.AddParameter("@LastName", DB.DataTypes.String, lastname);
			db.AddParameter("@Address", DB.DataTypes.String, address);
			
			break;


		case "Ticket":
			var TicketNumber = "" + Request.Form("TicketNumber");

			if (Helpers.IsNumeric(TicketNumber)) {
				TicketNumber = parseFloat(TicketNumber);
			}
			else {
				TicketNumber = 0;
			}
			
			queryName = "getHSandNonHSCustByTicketID";
			db.AddParameter("@TicketID", DB.DataTypes.String, TicketNumber);

			break;
					
	}
	
	db.QueryName = queryName;
	
	db.Execute();
		
	if(db.Success){
		rs = db.RecordSet;
	}
	
	//h.PrintLine(JSON.stringify(db));
	//Response.End();

} //if searchwhat <>""


%>

<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />


<script type="text/javascript" language="javascript">
	function OpenAcct(contract_id) {
		parent.location.href = "ApplicationFrameSet.asp?ContractID=" + contract_id;
	}
</SCRIPT>

<TITLE>Search Results</TITLE>
<LINK HREF="UniversalStyleSheet.css" REL="stylesheet" TYPE="text/css" />

<STYLE TYPE="text/css">

body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}

</STYLE>
</HEAD>

<% 
if (searchWhat == "" ){
	%>
		<body>
		</body>
	</html>
	<%
	Response.End();
}
else{

%>
	<BODY>
		<CAPTION CLASS="TableTitles">Results:</CAPTION><br />
		<TABLE WIDTH="300" BORDER="0" ALIGN="left" CELLPADDING="0" CELLSPACING="0">
			<TR>
				<TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperLeft.png"></TD>
				<TD WIDTH="260" HEIGHT="20" BACKGROUND="Images/TableUpperMiddle.png"></TD>
				<TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperRight.png"></TD>
			</TR>
			<TR>
				<TD WIDTH="20" BACKGROUND="Images/TableMiddleLeft.png"></TD>
				<TD>
					<TABLE WIDTH="260" BORDER="1" BORDERCOLOR="#009900" >
					
					<%
					if (rs.RecordCount == 0){
						%>
						<tr>
							<td WIDTH="170" BORDERCOLOR="#FFFFFF" BGCOLOR="#FFFFFF" CLASS="ListCell">
								<span class='ResultsName'>(No Results Found)</span>
							</td>
						</tr>
						<%
					}
					else{
						var link = "";
						var linkclose = "";
						
						while(!rs.EOF){
							var contractID = new String(rs("Contract_ID")); //new string because raw rs field doesnt allow indexOf()
							
							var entry=
								"<span class='ResultsName'>" 
									+ rs("first_name") 
									+ " " 
									+ rs("last_name") 
									+ (contractID.indexOf("NHS") > -1
										? "<span class='nonHS'> (Non-HomeSmart)</span>"
										: "")
								+ "</span><br/>" 
								+ "<span class='ResultsAddress'>" 
									+ rs("address") 
								+ "</span>"
							var link = "<a href='javascript: OpenAcct(\"" + rs("contract_id") + "\")'>";
							var linkclose = "</a>";
							%>	
  							<TR>
    							<TD WIDTH="170" BORDERCOLOR="#FFFFFF" BGCOLOR="#FFFFFF" CLASS="ListCell" onMouseOver="this.bgColor='#D2FFD2'" onMouseOut="this.bgColor='white'"><%= link %><%= entry %>
     							<%= linkclose %>
								</TD>
							</TR>
							<%
  							rs.MoveNext();
  						}
  					}
					%>
					</TABLE>
				</TD>
				<TD WIDTH="20" BACKGROUND="Images/TableMiddleRight.png"></TD>
			</TR>
			<TR>
				<TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableLowerLeft.png"></TD>
				<TD WIDTH="260" HEIGHT="20" BACKGROUND="Images/TableLowerMiddle.png"></TD>
				<TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableLowerRight.png"></TD>
			</TR>
		</TABLE>
	</BODY>
	</HTML>
<% } %>
